import 'package:dk_flutter_base/dk_ui.dart';
import 'package:dk_flutter_module_sale/r.dart';
import 'package:dk_flutter_module_sale/sale/sale_in/supervisor_visit/bean/bean_supervisor_visit.dart';

enum VisitHeaderType {
  hasButton,
  hasNoButton,
}

class HeaderOption {
  BeanSupervisorVisit headerBean;
  VisitHeaderType type;
  VoidCallback onPressedCallBack;

  HeaderOption.hasButton(this.headerBean, this.onPressedCallBack) {
    type = VisitHeaderType.hasButton;
  }

  HeaderOption.hasNoButton(this.headerBean) {
    type = VisitHeaderType.hasNoButton;
  }
}

class VisitHeaderWidget extends StatelessWidget {
  final HeaderOption headerOption;

  VisitHeaderWidget(this.headerOption);

  @override
  Widget build(BuildContext context) {
    bool hasBtn = headerOption.type == VisitHeaderType.hasButton;
    List<Widget> widgets = List();
    if (hasBtn) {
      widgets.add(getBtnWidget());
    } else {
      widgets.add(getPicWidget());
    }
    widgets.add(getInfoWidget());

    return Card(
      elevation: 10.0,
      color: Colors.white,
      margin: EdgeInsets.fromLTRB(18, 21, 14, 26),
      child: Stack(
        children: widgets,
      ),
    );
  }

  Widget getBtnWidget() {
    return Positioned(
      right: 18,
      bottom: 26,
      child: InkWell(
        child: Container(
          padding: EdgeInsets.all(5),
          decoration: BoxDecoration(
            border: Border.all(width: 1, color: Color(0xFF3DBCC6)),
            borderRadius: BorderRadius.circular(3),
          ),
          child: Text(
            "查看上周任务",
            style: TextStyle(
              color: Color(0xFF3DBCC6),
              fontSize: 13,
            ),
          ),
        ),
        onTap: () {
          //TODO 跳转
          headerOption.onPressedCallBack();
        },
      ),
    );
  }

  Widget getInfoWidget() {
    bool isLastWeek = headerOption.type == VisitHeaderType.hasButton;
    bool isFinish = headerOption.headerBean.finishStatus == "1" ? true : false;
    return Column(
      children: <Widget>[
        headerTitleWidget(!isLastWeek, isFinish),
        Row(
          children: <Widget>[
            headerTagertWidet(
                headerOption.headerBean.targetWeek.toString(), "陪访目标"),
            headerTagertWidet(
                headerOption.headerBean.finishWeek.toString(), "已完成"),
          ],
        ),
      ],
    );
  }

  Widget getPicWidget() {
    bool isFinish = headerOption.headerBean.finishStatus == "1" ? true : false;
    String imgName = isFinish
        ? R.imagesSaleinVisitFinishedPng
        : R.imagesSaleinVisitUnfinishedPng;
    return Positioned(
      right: 0,
      top: 0,
      bottom: 0,
      child: Image(
        image: AssetImage(imgName),
      ),
    );
  }
}

//头部标题
Widget headerTitleWidget(bool isLastWeek, bool isFinish) {
  String title;
  Color textColor;
  if (isLastWeek) {
    if (isFinish) {
      textColor = Color(0xFF3DBCC6);
      title = "恭喜你！已完成上周陪访任务";
    } else {
      textColor = Color(0xff333333);
      title = "很遗憾！未完成上周陪访任务";
    }
  } else {
    title = isFinish ? "本周任务已完成" : "本周任务未完成";
    textColor = Color(0xff666666);
  }

  return Container(
    padding: EdgeInsets.fromLTRB(8, 14, 0, 0),
    child: Row(
      children: <Widget>[
        Container(
          width: 5,
          height: 5,
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(2.5),
            color: Color(0xFF3DBCC6),
          ),
        ),
        Container(
          padding: EdgeInsets.only(left: 5),
          child: Text(
            title,
            style: TextStyle(
              color: textColor,
              fontSize: 14,
            ),
          ),
        ),
      ],
    ),
  );
}

//头部目标部分
Widget headerTagertWidet(String targetNum, String title) {
  targetNum ??= "0";
  return Container(
    padding: EdgeInsets.fromLTRB(14, 10, 14, 26),
    child: Column(
      children: <Widget>[
        Row(
          children: <Widget>[
            Text(
              targetNum,
              style: TextStyle(
                color: Color(0xff333333),
                fontSize: 20,
                fontWeight: FontWeight.bold,
              ),
            ),
          ],
        ),
        Row(
          children: <Widget>[
            Text(
              title,
              style: TextStyle(
                color: Color(0xff666666),
                fontSize: 12,
              ),
            ),
          ],
        ),
      ],
    ),
  );
}
